﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using CrystalDecisions.Shared;
using LPV_POS.Module;

    class Mod_khachhangchitietso
    {

        Mod_baocao baocao;
        public void rpt_baocaokhachhangchitietso(DataSet dset, ReportDocument rpt, string path_excel)
        {

            try
            {
                Mod_header_report header_report = new Mod_header_report();
                header_report.f_header_report(rpt);

                baocao = new Mod_baocao();

                CrystalDecisions.CrystalReports.Engine.TextObject str_thoigian;
                str_thoigian = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                if (Variable.str_tungay != "")
                {
                    str_thoigian.Text = Variable.str_tungay;
                }
                else
                {
                    str_thoigian.Text = "";
                }

                rpt.SetDataSource(dset.Tables[0]);
                rpt.DataDefinition.FormulaFields["NGAY_HE_THONG"].Text = "{dt_report.NGAY_HE_THONG}" + "";
                rpt.DataDefinition.FormulaFields["TONG_CONG"].Text = "{dt_report.TONG_CONG}" + "";
                rpt.DataDefinition.FormulaFields["TIEN_MAT"].Text = "{dt_report.TIEN_MAT}" + "";
                rpt.DataDefinition.FormulaFields["DC"].Text = "{dt_report.DC}" + "";  
                rpt.DataDefinition.FormulaFields["TY_LE"].Text = "{dt_report.TY_LE}" + "";
               

                //   xuat file excel
                ExportOptions CrExportOptions;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = path_excel;
                CrExportOptions = rpt.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                rpt.Export();

            }
            catch (Exception ex)
            {

                rpt.Dispose();
                Mod_messagebox mess = new Mod_messagebox();
                mess.messagebox_pos("Thông báo", "Xuất báo cáo thành file excel không thành công", loaithongbao.canhbao.GetHashCode());
                //throw;
            }
            rpt.Dispose();
        }




    }

